package com.gper.edu.vip.struct.proxy.impl;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author: ellis.guan
 * @Description:
 * @Date: 2020/3/2 21:33
 * @Version: 1.0
 */
public class EllisMatchMaker implements EllisInvocationHandler {
    private Object target;

    public EllisMatchMaker(Object target){
        this.target = target;
    }

    public Object getInstance() throws IllegalAccessException, InvocationTargetException, IOException, InstantiationException, NoSuchMethodException, ClassNotFoundException {
        return EllisProxy.newProxyInstance(new EllisClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆，开始为你物色对象");
        Object result = method.invoke(target,args);
        System.out.println("双方同意，可以开始交往");
        return result;
    }
}
